package com.example.znbk.znbklibrary.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.example.znbk.znbklibrary.R;

public class LoadingDialog extends Dialog {

    private Context context;
    private boolean isCancelable;//控制点击dialog外部是否dismiss
    private boolean isBackCancelable;//控制返回键是否dismiss
    private String txtLoading;

    public LoadingDialog(Context context, boolean isCancelable, boolean isBackCancelable) {
        super(context,R.style.MyBottomDialog);
        this.context = context;
        this.isCancelable = isCancelable;
        this.isBackCancelable = isBackCancelable;
        this.txtLoading = txtLoading;
    }

    public LoadingDialog(Context context, boolean isCancelable, boolean isBackCancelable,String txtLoading) {
        super(context,R.style.MyBottomDialog);
        this.context = context;
        this.isCancelable = isCancelable;
        this.isBackCancelable = isBackCancelable;
        this.txtLoading = txtLoading;
    }

    private TextView mTvLoading;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        View view = View.inflate(context,R.layout.dialog_loading,null);
        setContentView(view);//这行一定要写在前面
        setCancelable(isCancelable);//点击外部不可dismiss
        setCanceledOnTouchOutside(isBackCancelable);
        Window window = this.getWindow();
//        window.setDimAmount(0f);//去除遮罩
        //设置弹出动画
        window.setWindowAnimations(R.style.BottomDialogAnim);
        window.setGravity(Gravity.CENTER);
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);

        mTvLoading = findViewById(R.id.tv_loading);
        mTvLoading.setText(txtLoading);

    }

}
